package org.gitman.agentplatform.ui.summary;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.LinkedList;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumnModel;

import org.gitman.agentplatform.core.SimulationStatistic;
import org.gitman.agentplatform.ui.MainFrame;
import org.gitman.agentplatform.ui.actions.ActionsManager;

public class MultirunSummaryDialog extends JDialog{

	public MultirunSummaryDialog(LinkedList<SimulationStatistic> statistics, MainFrame mainFrame) {
		ActionsManager actionsManager = mainFrame.getActionsManager();
		
		setTitle("Multirun simulation summary");
		setLayout(new BorderLayout());
		
		
		MultirunSummaryTabelModel model = new MultirunSummaryTabelModel(statistics);
		JTable table = new JTable(model);
		TableColumnModel cm = table.getColumnModel();
		int [] widths = model.getWidths();
		for(int i=0;i<widths.length;i++){		
			cm.getColumn(i).setPreferredWidth(widths[i]);
		}
		JScrollPane panel = new JScrollPane(table);
		add(panel, BorderLayout.CENTER);		
		
		JPanel optionsPanel = new JPanel(new GridLayout(1, 5));
		optionsPanel.add(new JButton(actionsManager.mulitrunExport2CSVAction));
		optionsPanel.add(new JButton(actionsManager.export2gnuplot));
		add(optionsPanel, BorderLayout.NORTH);
		
		setSize(640, 640);
		setLocationRelativeTo(mainFrame);
	}
}
